import {Information} from "../../models/information";
import {dateToTimestamp, promisic} from "../../util/util";
import {config} from "../../config/config";
import {showToast} from "../../util/ui";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    infoDetail: null,
    updateTime: null,
    showLoading: true
  },
  async onLoad(options) {
    //详情id
    const res = await Information.doApiGetInForListById(options.id)
    await this.openFile(res.data.enclosure)
    this.setData({
      infoDetail: res.data,
      updateTime: dateToTimestamp(res.data.updateTime),
      fileUrl: config.apiBaseUrl + res.data.enclosure,
      showLoading: false
    })
  },
  // async openFile(fileUrl) {
  //   const completeFileUrl = config.apiBaseUrl + fileUrl
  //   try {
  //     const fileTempRes = await promisic(wx.downloadFile)({
  //       url: completeFileUrl
  //     })
  //     const fileTempPath = fileTempRes.tempFilePath
  //     if (!fileTempPath) return showToast('解析文件出现错误')
  //     await wx.openDocument({
  //       filePath: fileTempPath
  //     })
  //   } catch (e) {
  //     showToast('解析文件出现错误')
  //   }
  // }
})
